package Syntactic;

import Semantic.Symbol;
import Util.List;

public class Environment 
{
	public List<Symbol> symbolTable;
    public Environment previous;
    private String envName;			// just for information
    
    public Environment(String name, Environment previous)
    {
    	this.envName = name;
    	this.symbolTable = new List<Symbol>();
        this.previous  = previous;
    }
    
    public Environment(String name)
    {
        this(name, null);
    }
    
    public String getEnvironmentName()
    {
    	return this.envName;
    }
    
    public void addSymbol(Symbol symbol)
    {
    	this.symbolTable.addNode(symbol);
    }
    
    public void updateSymbol (Symbol symbol)
    {
    	this.symbolTable.updateNode(symbol);
    }
    
    // now it's looking to all parent environments too
    public Symbol getSymbol(String value)
    {
    	Environment aux = this;
    	Symbol result = null;
    	
    	do
    	{
    		result = aux.symbolTable.getNode(new Symbol(value));
    		aux = aux.previous;
    	} while (result == null && aux != null);
    	    	
    	return result;
    }
    
    
    public static void main(String[] args) {
	}	
}
